package com.project.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.project.bean.DeptBean;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface IDeptMapper extends BaseMapper<DeptBean> {
    @Select("SELECT d.*,COUNT(e.`fk_deptId`)emNum FROM t_dept d" +
            " LEFT JOIN t_employee e ON d.`pk_deptId`=e.`fk_deptId` GROUP BY d.`pk_deptId`")
    @ResultMap("deptMap")
    public List<DeptBean> findAll();
    @Delete("delete from t_employee where pk_employeeId = #{id};"+
    "delete from t_dept where pk_deptId = #{id}")
    public void delCasede(Integer id);

    @Delete("update t_employee set fk_deptId = null where fk_deptId=#{id};"+
            "delete from t_dept where pk_deptId = #{id}")
    public void delSetNull(Integer id);
}
